// pages/workSignAddEdit/workSignAddEdit.js
const app = getApp()
const api = app.globalData.api

Page({

  /**
   * 页面的初始数据
   */
  data: {
    info:{},
    reason:'',
    signTime:'',
    time_popup_show:false,
    currentTimestamp:'',
  },

  chooseTime(){
    let currentTimestamp = this.data.signTime?new Date(api.rowTocol(this.data.signTime)).getTime():new Date().getTime();
    this.setData({
      time_popup_show:true,
      currentTimestamp:currentTimestamp
    })
  },
  /**日期选择确认 */
  timeConfirm(e){
    this.setData({
      currentTimestamp:e.detail,
      signTime:api.formatDateCRM('Y-m-d H:i:s',e.detail),
      time_popup_show:false
    })
  },
  timeCancel(e){
    this.setData({
      time_popup_show:false
    })
  },
  commit(e){
    let para = e.detail.value;
    console.log(para)
    para.id = this.data.info.id?this.data.info.id:'';
   
    api.curlPost('?cla=workSignAddApp&fun=commitEdit',para).then((res)=>{
        wx.redirectTo({
          url: '../workSignAddInfo/workSignAdInfo?id='+res.data.id,
        })
    })
   
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = options.id;
    let that = this;
    if(!api.isBlank(id)){
      api.curlPost('?cla=workSignAddApp&fun=editPage',{id:id}).then((res)=>{
        that.setData({
          info:res.data.result,
          signTime:res.data.result.signTime
        })
      })
    }
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})